﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CIIS.Common;

namespace CIIS
{
    public partial class RoleEdit : BaseForm
    {
        public RoleEdit()
        {
            InitializeComponent();
            LoadLookUp();
        }
        public RoleEdit(Contract.Domain.t_sys_role _role)
        {
            InitializeComponent();
            LoadLookUp();
            role = _role;
            textEdit1.Text = role.ROLE_NAME;
            lookupedit.EditValue=role.ROLE_TYPE;
            if (role.SORT_NO.HasValue)
            {
                textEdit3.Text = role.SORT_NO.Value.ToString();
            }
            memoEdit1.Text = role.ROLE_INFO;
        }
        private void LoadLookUp()
        {
            DevControlUtils.Instance.InitLookUpEditByEnum(lookupedit, typeof(RoleType));
        }
        private Contract.Domain.t_sys_role role
        {
            get;
            set;
        }
        private void simpleButton1_Click(object sender, EventArgs e)
        {
            if (role == null)
            {
                role = new Contract.Domain.t_sys_role();
                role.State.MarkNew();
            }
            if (string.IsNullOrEmpty(textEdit1.Text))
            {
                MessageBox.Show("名称不能空！");
                return;
            }
            role.ROLE_NAME = textEdit1.Text;
            var o = lookupedit.GetSelectedDataRow() as DropDownListItem;
            if (o != null)
            {
                role.ROLE_TYPE =o.Value.ToString();
            }
            else
            {
                MessageBox.Show("角色类型不能空！");
            }
         
            if (!string.IsNullOrEmpty(textEdit3.Text))
            { 
                int a = 0;
                if (int.TryParse(textEdit3.Text, out a))
                {
                    role.SORT_NO = a;
                }
                else
                {
                    MessageBox.Show("序号不是数值！");
                    return;
                }
            }
            role.ROLE_INFO = memoEdit1.Text;
            dao.Dao.SaveOrUpdate(role);
            DialogResult = System.Windows.Forms.DialogResult.OK;
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
